<?php

	/**
	 * @see Bike_Initial
	 */
	require_once 'Bike/Initial.php';
	
	
	class Bike_Cli extends Bike_Initial
	{        static protected $_cli_path;
        static protected $_php_path = 'php';
        static protected $_instance;

        static public function getInstance()
        {        	if(is_null(self::$_instance))
        	{        		self::$_instance = new self();
        	}
        	return self::$_instance;
        }

        static public function setCliPath($CliPath)
        {        	self::$_cli_path = $CliPath;
        }

        static public function getCliPath()
        {
        	return self::$_cli_path;
        }

        static public function setPhpPath($PhpPath)
        {
        	self::$_php_path = $PhpPath;
        }

        static public function getPhpPath()
        {
        	return self::$_php_path;
        }

        static public function execute()
        {        	$Args = func_get_args();
        	$className = array_shift($Args);
        	$command = self::getPhpPath().' '.escapeshellcmd(self::getCliPath()).' -c '.escapeshellarg($className).' '.(sizeof($Args) ? join(' ', array_map('escapeshellarg', array_map('serialize', $Args))) : '');
        	$output = shell_exec($command);
            return (object) array(
            	'output' => $output,
            	'htmlOutput' => nl2br($output),
            );
        }
	}
